package com.fk.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fk.dao.impl.UserDaoImpl;
import com.fk.entity.User;
import com.fk.uitl.Result;

public class MessageServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String username = request.getParameter("username"); // 获取前台传来的参数
		String phone = request.getParameter("phone");
		String email =request.getParameter("email");
		String content = request.getParameter("content");
		
		User user = new User(username, phone, email, content);	//创建user对象
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		UserDaoImpl uDao = new UserDaoImpl();	// 创建User实体类
		int n = uDao.addMessage(user);
		if(n > 0 ) {
			out.print(Result.toClient(true, "留言成功", ""));
		}else {
			out.print(Result.toClient(false, "留言失败", "服务器不想理你"));
		}
		out.flush();
		out.close();
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}

